package com.zzyl.controller;

import com.aliyun.iot20180120.models.QueryThingModelPublishedResponseBody;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.IotService;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/iot")
@Api(tags = "管理端 - 物联网iot相关接口")
public class IotController {

    @Autowired
    private IotService iotService;

    /**
     * 同步产品列表
     * @return
     */
    @PostMapping("/syncProductList")
    @ApiOperation(value = "从物联网平台同步产品列表")
    public ResponseResult syncProductList(){
        iotService.syncProductList();
        return ResponseResult.success();
    }

    @ApiOperation("获取所有产品信息")
    @GetMapping("/allProduct")
    public ResponseResult<List<ProductVo>> allProduct(){
        List<ProductVo> voList = iotService.allProduct();
        return ResponseResult.success(voList);
    }

    @ApiOperation("新增设备数据")
    @PostMapping("/RegisterDevice")
    public ResponseResult registerDevice(@RequestBody DeviceDto dto){
        iotService.registerDevice(dto);
        return ResponseResult.success();
    }

    /**
     * 分页查询
     * @param dto
     * @return
     */
    @GetMapping("/pageQueryDevice")
    public ResponseResult<PageResponse<DeviceVo>> findByPage(DevicePageQueryDto dto){
        PageResponse<DeviceVo> page = iotService.findByPage(dto);
        return ResponseResult.success(page);
    }

    /**
     * 查询设备的详细信息
     * @param dto
     * @return
     */
    @PostMapping("/QueryDeviceDetail")
    public ResponseResult<DeviceVo> findDeviceDetail(@RequestBody DeviceDto dto){
        DeviceVo deviceVo = iotService.findDeviceDetail(dto);
        return ResponseResult.success(deviceVo);
    }

    /**
     * 查询产品的物模型数据
     * @param dto
     * @return
     */
    @PostMapping("/QueryThingModelPublished")
    public ResponseResult<QueryThingModelPublishedResponseBody.QueryThingModelPublishedResponseBodyData> queryThingModelPublished(@RequestBody DeviceDto dto){
        QueryThingModelPublishedResponseBody.QueryThingModelPublishedResponseBodyData data = iotService.queryThingModelPublished(dto);
        return ResponseResult.success(data);
    }
}
